#ifndef GROUPITEMDATA_H
#define GROUPITEMDATA_H

#include <QObject>
#include <QTime>
#include <QMap>
//#include <QTableWidget>

class QTableWidget;
namespace BatchFeed {
    enum ClientConnectType{
        ClientConType_Error = 1,
        ClientConType_WeighConnected ,
        ClientConType_StartedWeigh ,
        ClientConType_FinishedWeigh ,
        ClientConType_ReadyReadWeighValue ,
        ClientConType_WeighError ,
        ClientConType_PutConnected,
        ClientConType_StartPut,
        ClientConType_FinishedPut,
        ClientConType_PutError
    };
}
class QDateTime;
class QTimeEdit;

class GroupItemData : public QObject
{
    Q_OBJECT
public:
    explicit GroupItemData(QObject *parent = 0);

    GroupItemData(const GroupItemData &user){
        copy(user);
    }

    GroupItemData &operator=(const GroupItemData & other){
        copy(other);

        return *this;
    }

    GroupItemData &operator<<(GroupItemData &other){
        copy(other);
        return *this;
    }

    GroupItemData &operator>>(GroupItemData &other){
        copy(other);
        return *this;
    }

    QString next();//next table name of key

    QString getItemText(){return m_itemText;}
    QString getIpadd(){return m_Ipadd;}
    QString getItemIndex(){return m_itemIndex;}
    QString getGroupNum(){return m_groupNum;}
    QString getDBFileName(){return m_filedb;}
    QString getEXLFileName(){return m_fileexl;}
    QString currentTable();//返回当前餐次

    QTime getStartTime(){return m_starttime;}
    QTime getCycleTime(){return m_cycletime;}
    int getCount(){return m_count;}
    qint32 getCycleMsecs(int index = 0);

    QTime getFirstStartTime();
    QTime getFirstCycleTime();
    int getFirstCount();
    qint32 getFirstCycleMsecs();

    QTime getTBStartTime(const QString &tbname);
    QTime getTBCycleTime(const QString &tbname);
    int getTBCount(const QString &tbname);
    qint32 getTBCycleMsecs(const QString &tbname);

    QMap<QString,QTime> getTBStartTimes(){return m_mapStartTime;}
    QMap<QString,QTime> getTBCycleTimes(){return m_mapCycleTime;}
    QMap<QString,int> getTBCounts(){return m_mapCount;}

    QMap<QString,QString> getCurrentPutData(){return m_putValue;}

    QTableWidget* getTableWidget(QString tbName);

//    QHash<QString,QString> getWeight(){return m_weighValue;}

    bool IsEnable(){return m_IsEnable;}
    bool IsIgnorError(){return m_IsIgnorError;}

    void setCurrentTb(QString str){m_currentTb = str;}
    void setItemText(QString str){m_itemText = str;}
    void setIpadd(QString str){m_Ipadd = str;}
    void setItemIndex(QString str){m_itemIndex = str;}
    void setGroupNum(QString str){m_groupNum = str;}
    void setDBFileName(QString str){m_filedb = str;}
    void setEXLFileName(QString str){m_fileexl = str;}

    void setStartTime(QTime time){m_starttime = time;}//all.
    void setCycleTime(QTime time){m_cycletime = time;}
    void setCount(int count){m_count = count;}

    void setEnable(bool flag){m_IsEnable = flag;}
    void setIgnorError(bool flag){m_IsIgnorError = flag;}

    void insertTBStartTime(const QString &tbname, const QTime &time);
    void insertTBCycleTime(const QString &tbname, const QTime &time);
    void insertTBCount(const QString &tbname, const int &count);

    void removeItem(QString key);

    void setputTable(QString str);

    void setCurrentPutData(QMap<QString,QString> map){m_putValue = map;}

    void setTableWidget(QString tblname,QTableWidget* tblwnd);

//    void setWeight(QHash<QString,QString> weighvalue){m_weighValue = weighvalue;}
private:
    QString m_itemText;
    QString m_Ipadd;
    QString m_itemIndex;
    QString m_groupNum;
    QString m_filedb,m_fileexl;
    QTime m_starttime;
    QTime m_cycletime;
    QString m_currentTb;//第?餐
    int m_count;
    bool m_IsEnable;
    bool m_IsIgnorError;//TODO:应设置初始值

    QMap<QString,QTableWidget*> m_MapTblWnds;//对应餐数数据表格,存放对应当前数据（投料值、返回值等）

    QList<QString> m_hadPutTb;
    //group map.
    QMap<QString,QTime> m_mapStartTime;
    QMap<QString,QTime> m_mapCycleTime;
    QMap<QString,int> m_mapCount;

    QMap<QString/*boxnum*/,QString/*boxvalue*/> m_putValue;

protected:
    virtual void copy(const GroupItemData& other);

};

Q_DECLARE_METATYPE(GroupItemData)
#endif // GROUPITEMDATA_H
